from sklearn import metrics
from sklearn import datasets
from sklearn.model_selection import cross_val_predict, train_test_split
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
from sklearn.linear_model import LinearRegression
from sklearn.ensemble import BaggingRegressor
model_BaggingRegressor = BaggingRegressor()

# %matplotlib inline

Regression = LinearRegression()

mpl.rcParams['font.family'] = ['sans-serif']
mpl.rcParams['font.sans-serif'] = ['SimHei']
mpl.rcParams['axes.unicode_minus'] = False

data = pd.read_excel('人口数量.xlsx')

X = data.iloc[:, 2:10]
Y = data['总人口']

x_train = X.head(14)
x_test = X.tail(4)
y_train = Y.head(14)
y_test = Y.tail(4)

lr = Regression
lr.fit(x_train, y_train)
y_pred = lr.predict(x_test)

MSE = metrics.mean_squared_error(y_test, y_pred)
RMSE = np.sqrt(metrics.mean_squared_error(y_test, y_pred))

print('MSE:', MSE)
print('RMSE:', RMSE)

print(lr.score(x_train, y_train))
print(y_test)
print(y_pred)
